package com.open.rbac.constant;

import java.security.Permission;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import lombok.Getter;

import org.springframework.security.core.authority.SimpleGrantedAuthority;

/**
 * 角色
 *
 * @author Riche's
 * @since 2025/5/25
 */
public enum Role {

    USER(Collections.emptySet()),

    ADMIN(Collections.emptySet());

    @Getter
    private final Set<Permission> permissions;

    Role(Set<Permission> permissions) {
        this.permissions = permissions;
    }

    public List<SimpleGrantedAuthority> getAuthority() {
        return getPermissions().stream().map(permission ->
                        new SimpleGrantedAuthority(permission.getName()))
                .collect(Collectors.toList());
    }

}
